package tree.avl;

import java.util.Comparator;

/**
 * Created by root on 3/7/17.
 */
public class AvlTree<T> {

    private AvlNode<T> root;
    private Comparator<? super T> cmp;

    public void insert(T x){
        root = root.insert(x,root);
    }


    public AvlTree() {
    }

    public AvlTree(Comparator<? super T> cmp) {
        this.root = null;
        this.cmp = cmp;
    }

    public AvlTree(AvlNode<T> root) {
        this.root = root;
    }

    public AvlTree(AvlNode<T> root, Comparator<? super T> cmp) {
        this.root = root;
        this.cmp = cmp;
    }

    void printTree(AvlNode<T> root){
        if(root==this.root)
            System.out.println("--------root---------"+root.getElement().toString());
        System.out.println(root.element.toString());
        if(root.left!=null){
            System.out.print("left--");
            printTree(root.left);
        }
        if(root.right!=null){
            System.out.print("right--");
            printTree(root.right);
        }
    }

    public AvlNode<T> getRoot() {
        return root;
    }

    public void setRoot(AvlNode<T> root) {
        this.root = root;
    }
}
